<?php
/*
Simple:Press
Installer/Upgrader Error Handler
$LastChangedDate: 2010-04-18 17:22:20 +0100 (Sun, 18 Apr 2010) $
$Rev: 3920 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
	die('Access Denied');
}

function sf_install_error($errno, $errstr, $errfile, $errline)
{
	$logfile = dirname(__FILE__).'/install-error.log';
	$uselog = is_writable($logfile);

    # timestamp for the error entry.
    $dt = date('Y-m-d H:i:s (T)');

    $stop = false;

    # Give the error level a name
    # Set a switch indicating whether the error level should make the script exit
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $error_msg = 'Notice';
            break;

        case E_WARNING:
        case E_USER_WARNING:
            $error_msg = 'Warning';
            break;

        case E_STRICT:
            $error_msg = 'Strict';
            break;

        case E_ERROR:
        case E_USER_ERROR:
            $error_msg = 'Install Error: (Fatal) ';
            $stop = true;
            break;

        # Handle the possibility of other, unknown problems
        default:
            $error_msg = 'Install Error: (Unknown) ';
            $stop = true;
            break;
    }

	$error_msg.= "[$errno] [$dt] $errstr on line $errline in file $errfile \n";

	if($uselog)
	{
		error_log($error_msg, 3, dirname(__FILE__).'/install-error.log');
	}

	if ($stop == true)
	{
		echo $error_msg;
		die();
	}
	return;
}

$old_error_handler = set_error_handler('sf_install_error');

?>